// $ANTLR 2.7.6 (2005-12-22): "multiValueExpression.g" -> "MultiValueExpression.java"$

package com.aote.expression.antlr;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.aote.expression.ParamProcessorFactory;
import com.aote.expression.function.StringFunctionFactory;
import java.util.Map;
import java.util.List;
import java.util.LinkedList;
import java.util.Collection;
import org.w3c.dom.Element;

import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.ANTLRException;
import antlr.LLkParser;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;

public class MultiValueExpression extends antlr.LLkParser       implements MultiValueExpressionTokenTypes
 {

	private String getParamString(String param) {
		int len = param.length();
		return param.substring(1, len - 1);
	}

    private Collection process(String param,Map attrs,HTMLBasicComponent component,Element config)
    {
        return ParamProcessorFactory.getInstance().process(param,attrs,component,config);
    }

protected MultiValueExpression(TokenBuffer tokenBuf, int k) {
  super(tokenBuf,k);
  tokenNames = _tokenNames;
}

public MultiValueExpression(TokenBuffer tokenBuf) {
  this(tokenBuf,1);
}

protected MultiValueExpression(TokenStream lexer, int k) {
  super(lexer,k);
  tokenNames = _tokenNames;
}

public MultiValueExpression(TokenStream lexer) {
  this(lexer,1);
}

public MultiValueExpression(ParserSharedInputState state) {
  super(state,1);
  tokenNames = _tokenNames;
}

	public final Collection  expression(
		Map attrs,HTMLBasicComponent component,Element config
	) throws RecognitionException, TokenStreamException {
		Collection result=null;
		
		Token  p = null;
		
			Collection b;
			
		
		
		try {      // for error handling
			switch ( LA(1)) {
			case ID:
			{
				b=function(attrs,component,config);
				result=b;
				break;
			}
			case PARAMS:
			{
				p = LT(1);
				match(PARAMS);
				result=process(getParamString(p.getText()),attrs,component,config);
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_0);
		}
		return result;
	}
	
	public final Collection  function(
		Map attrs,HTMLBasicComponent component,Element config
	) throws RecognitionException, TokenStreamException {
		Collection result=null;
		
		Token  id = null;
		
			List pl;
		
		
		try {      // for error handling
			{
			id = LT(1);
			match(ID);
			match(LEFT);
			pl=paramList(attrs,component,config);
			match(RIGHT);
			}
			result=StringFunctionFactory.getInstance().invoke(id.getText(), pl);
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_0);
		}
		return result;
	}
	
	public final List  paramList(
		Map attrs,HTMLBasicComponent component,Element config
	) throws RecognitionException, TokenStreamException {
		List result=new LinkedList();
		
		
			Object p;
			Object p1;
		
		
		try {      // for error handling
			p=paramItem(attrs,component,config);
			result.add(p);
			{
			_loop6:
			do {
				if ((LA(1)==COMMA)) {
					match(COMMA);
					p1=paramItem(attrs,component,config);
					result.add(p1);
				}
				else {
					break _loop6;
				}
				
			} while (true);
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_1);
		}
		return result;
	}
	
	public final Object  paramItem(
		Map attrs,HTMLBasicComponent component,Element config
	) throws RecognitionException, TokenStreamException {
		Object result=null;
		
		Token  s = null;
		Token  v = null;
		
			Collection b;
		
		
		try {      // for error handling
			switch ( LA(1)) {
			case PARAMS:
			case ID:
			{
				b=expression(attrs,component,config);
				result=b;
				break;
			}
			case STRING:
			{
				s = LT(1);
				match(STRING);
				result=getParamString(s.getText());
				break;
			}
			case NUMBER:
			{
				v = LT(1);
				match(NUMBER);
				result=new Double(v.getText());
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_0);
		}
		return result;
	}
	
	
	public static final String[] _tokenNames = {
		"<0>",
		"EOF",
		"<2>",
		"NULL_TREE_LOOKAHEAD",
		"PARAMS",
		"ID",
		"LEFT",
		"RIGHT",
		"COMMA",
		"STRING",
		"NUMBER",
		"WS"
	};
	
	private static final long[] mk_tokenSet_0() {
		long[] data = { 384L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
	private static final long[] mk_tokenSet_1() {
		long[] data = { 128L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
	
	}
